home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / LIB / MKTEMPNM.C < prev    next >
C/C++ Source or Header  |  1993-04-10  |  3KB  |  84 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    m k t e m p n m . c                                             */
  3. /*                                                                    */
  4. /*    Host Support routines for UUPC/extended                         */
  5. /*                                                                    */
  6. /*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of hlib.c                         ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <limits.h>
  16. #include <time.h>
  17.  
  18. #ifdef __GNUC__
  19. #include <unistd.h>
  20. #else
  21. #include <io.h>
  22. #endif
  23.  
  24. /*--------------------------------------------------------------------*/
  25. /*                          RCS Information                           */
  26. /*--------------------------------------------------------------------*/
  27.  
  28. /*
  29.  *    $Id: MKTEMPNM.C 1.3 1993/04/11 00:31:04 ahd Exp $
  30.  *
  31.  *    Revision history:
  32.  *    $Log: MKTEMPNM.C $
  33.  *     Revision 1.3  1993/04/11  00:31:04  ahd
  34.  *     Global edits for year, TEXT, etc.
  35.  *
  36.  * Revision 1.2  1992/11/19  02:57:07  ahd
  37.  * drop rcsid
  38.  *
  39.  * Revision 1.1  1992/11/16  05:00:26  ahd
  40.  * Initial revision
  41.  *
  42.  */
  43.  
  44.  
  45. /*--------------------------------------------------------------------*/
  46. /*                    UUPC/extended include files                     */
  47. /*--------------------------------------------------------------------*/
  48.  
  49. #include "lib.h"
  50. #include "hlib.h"
  51.  
  52. /*--------------------------------------------------------------------*/
  53. /*                          Global variables                          */
  54. /*--------------------------------------------------------------------*/
  55.  
  56. currentfile();
  57.  
  58. /*--------------------------------------------------------------------*/
  59. /*    m k t e m p n a m e                                             */
  60. /*                                                                    */
  61. /*    Generate a temporary name with a pre-defined extension          */
  62. /*--------------------------------------------------------------------*/
  63.  
  64. char *mktempname( char *buf, char *extension)
  65. {
  66.    static size_t file = 0;
  67.    if (buf == NULL)           /* Do we need to allocate buffer?         */
  68.    {
  69.       buf = malloc( FILENAME_MAX );
  70.       checkref(buf);
  71.    } /* if */
  72.  
  73.    for (file++ ; file < INT_MAX ; file++ )
  74.    {
  75.       sprintf(buf,"%s/uupc%04.4x.%s", E_tempdir, file, extension);
  76.       if ( access( buf, 0 ))  /* Does the host file exist?           */
  77.          break;               /* No  --> Use the name                */
  78.    } /* for */
  79.  
  80.    printmsg(5,"Generated temporary name: %s",buf);
  81.    return buf;
  82.  
  83. } /* mktempname */
  84.